package cmpe273.proj1.utilities;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class Utilities {
	
	public final static String STRING_LENGTH_ERROR = "%s longer than %d characters.%n";
	public final static String STRING_LENGTH_ERROR_NOTEQUAL = "%s is not exactly %d characters.%n";
	public final static String ID_FORMAT_ERROR = "Invalid ID format.%n";
	public final static String ZIPCODE_FORMAT_ERROR = "Invalid Zipcode format.%n";
	public final static String STATE_FORMAT_ERROR = "Invalid state abbreviation.%n";
	public static HashMap<String, String> StateAbbreviationsAndNames;
	
	static {
		StateAbbreviationsAndNames = new HashMap<String, String>();
		StateAbbreviationsAndNames.put("AL", "Alabama");
		StateAbbreviationsAndNames.put("AK", "Alaska");
		StateAbbreviationsAndNames.put("AZ", "Arizona");
		StateAbbreviationsAndNames.put("AR", "Arkansas");
		StateAbbreviationsAndNames.put("CA", "California");
		StateAbbreviationsAndNames.put("CO", "Colorado");
		StateAbbreviationsAndNames.put("CT", "Connecticut");
		StateAbbreviationsAndNames.put("DE", "Delaware");
		StateAbbreviationsAndNames.put("DC", "District of Columbia");
		StateAbbreviationsAndNames.put("FL", "Florida");
		StateAbbreviationsAndNames.put("GA", "Georgia");
		StateAbbreviationsAndNames.put("HI", "Hawaii");
		StateAbbreviationsAndNames.put("ID", "Idaho");
		StateAbbreviationsAndNames.put("IL", "Illinois");
		StateAbbreviationsAndNames.put("IN", "Indiana");
		StateAbbreviationsAndNames.put("IA", "Iowa");
		StateAbbreviationsAndNames.put("KS", "Kansas");
		StateAbbreviationsAndNames.put("KY", "Kentucky");
		StateAbbreviationsAndNames.put("LA", "Louisiana");
		StateAbbreviationsAndNames.put("ME", "Maine");
		StateAbbreviationsAndNames.put("MD", "Maryland");
		StateAbbreviationsAndNames.put("MA", "Massachusetts");
		StateAbbreviationsAndNames.put("MI", "Michigan");
		StateAbbreviationsAndNames.put("MN", "Minnesota");
		StateAbbreviationsAndNames.put("MS", "Mississippi");
		StateAbbreviationsAndNames.put("MO", "Missouri");
		StateAbbreviationsAndNames.put("MT", "Montana");
		StateAbbreviationsAndNames.put("NE", "Nebraska");
		StateAbbreviationsAndNames.put("NV", "Nevada");
		StateAbbreviationsAndNames.put("NH", "New Hampshire");
		StateAbbreviationsAndNames.put("NJ", "New Jersey");
		StateAbbreviationsAndNames.put("NM", "New Mexico");
		StateAbbreviationsAndNames.put("NY", "New York");
		StateAbbreviationsAndNames.put("NC", "North Carolina");
		StateAbbreviationsAndNames.put("ND", "North Dakota");
		StateAbbreviationsAndNames.put("OH", "Ohio");
		StateAbbreviationsAndNames.put("OK", "Oklahoma");
		StateAbbreviationsAndNames.put("OR", "Oregon");
		StateAbbreviationsAndNames.put("PA", "Pennsylvania");
		StateAbbreviationsAndNames.put("RI", "Rhode Island");
		StateAbbreviationsAndNames.put("SC", "South Carolina");
		StateAbbreviationsAndNames.put("SD", "South Dakota");
		StateAbbreviationsAndNames.put("TN", "Tennessee");
		StateAbbreviationsAndNames.put("TX", "Texas");
		StateAbbreviationsAndNames.put("UT", "Utah");
		StateAbbreviationsAndNames.put("VT", "Vermont");
		StateAbbreviationsAndNames.put("VA", "Virginia");
		StateAbbreviationsAndNames.put("WA", "Washington");
		StateAbbreviationsAndNames.put("WV", "West Virginia");
		StateAbbreviationsAndNames.put("WI", "Wisconsin");
		StateAbbreviationsAndNames.put("WY", "Wyoming");
	}
	
	public static JSONObject toJsonObject(String str)
	{
		JSONObject obj;
		try {
			obj = new JSONObject(str);
		} catch (JSONException e) {
			obj = null;
			e.printStackTrace();
		}
		
		return obj;
	}
	
	public static JSONArray toJsonArray(String str)
	{
		JSONArray arr;
		try {
			arr = new JSONArray(str);
		} catch (JSONException e) {
			arr = null;
			e.printStackTrace();
		}
		
		return arr;
	}
}
